<?php
include('class/class_connect.php');
include('class/class_page.php');
include('class/city_rus.php');
include('class/class_checkGetData.php');
include('class/abstract/class_paginator.php');
foreach($_GET as $key=>$val)
{
	$_GET[$key]=checkGetData::safetyCheck($val);
}
foreach($_POST as $key=>$val)
{
	$_POST[$key]=checkGetData::safetyCheck($val);
}
session_start();
if($_POST['sendMessage'])
{
	$name=mb_substr($_POST['name'], 0, 60, 'utf-8');
	$text=mb_substr($_POST['text'], 0, 2000, 'utf-8');
	$data=date('Y-m-d H:i:s');
	$user=$_SESSION['login'];
	$dataToInsert="name='$name', stext='$text', data='$data', user='$user'";
	if(strlen($text)>10)
	{
		$aConnect=new connect('main');
		$aConnect->insert_data('hostbook', $dataToInsert);
		$to='novichkovv@bk.ru';
		$subject='Гостевая книга на Pro-gorod.com';
		$mail='
		имя: '.$name.'<br />
		запись: '.$text.'<br />
		пользователь: '.$user.'<br />
		дата: '.$data.'
		';
		$headers  = 'MIME-Version: 1.0' . "\r\n";
		$headers .= 'Content-type: text/html; charset=utf-8' . "\r\n";
		$headers .= 'To: <'.$to.'>' . "\r\n";
		$headers .= 'From: pro-gorod.com <no-reply@pro-gorod.com>' . "\r\n";
		mail($to, $subject, $mail, $headers);
		header('location: hostbook.php?city='.$_GET['city']);
		exit;
	}
}
class about extends page
{
	function __construct()
	{
		parent::__construct();
	}
	function title()
	{
		echo 'Гостевая книга';
	}
	function maincontent()
	{
		echo ('
		<link rel="stylesheet" type="text/css" href="style/about.css" />
		<div class="about">
			<div class="headerAbout">
				<h2>Гостевая книга</h2>
			</div>
			<p id="firstString" align="center">
				Вы можете оставить свою запись в нашей гостевой книге.
			</p>
			<div class="backForm">
				<form name="" action="" method="post">
					<div class="signature">
					Как Вас зовут:
					</div>
		        	<input class="backFormInput" name="name" type="text" value="">
		        	<div class="signature">
					Ваша запись:
					</div>
		        	<textarea name="text" cols="75" rows="6"></textarea><br />
		        	<input type="submit" value="Сохранить" name="sendMessage">
				</form>
			</div>
		');
		$messages=new messPaginator();
		echo ('
		</div>
		');
	}
}
class messPaginator extends paginator
{
	var $res=array();
	var $messNum;
	var $row=array();
	function __construct()
	{
		$aConnect=new connect('main');
		$this->res=$aConnect->select_all('hostbook', "ORDER BY data DESC");
		$this->messNum=mysql_num_rows($this->res);
		parent::__construct(20);
	}
	function pageContent()
	{
		echo ('
		<div class="hostBookMessages">
		');
		while($row=mysql_fetch_array($this->res))
		{			$date=date_create($row['data']);
			$date=date_format($date, "d-m-Y H:m");			echo ('
			<div class="hostBookMessage">
				<div class="hostBookData">
					'.$date.'
				</div>
				<div class="hostBookText">
					'.$row['stext'].'
				</div>
				<div class="hostBookName">
					'.$row['name'].'
				</div>
			</div>
			');		}
		echo ('
		</div>
		');
	}
	function countRows()
	{
		return($this->messNum);
	}
}
$aPage=new about();

?>